package com.Food;

import java.io.Console;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;


import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;

public class menu extends Activity{
public int count =0;
public int oldCount=1;

private static final String TAG = "Menu";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
	    
		Button b = (Button) this.findViewById(R.id.but_newMenu);
		
		Intent i = getIntent();
		Bundle b2 = i.getExtras();
		final String text = b2.getString("kategori");
		final String postnr = b2.getString("post");
		
		
		Log.v(TAG, text);
		Log.v(TAG, postnr);
		
		
		b.setOnClickListener(new View.OnClickListener() 
	    {
			@Override
			public void onClick(View v) 
			{
				Log.v(TAG, text);
				random(text);
				
				
			}
		});
	}
	
	private void random(String txt)
	{
		if(txt.equals("Pizza"))
		{
			pizza();
		}
		if(txt.equals("Burger"))
		{
			burger();
		}
	}
	
	private void pizza()
	{
		Random ran = new Random();
		count =0;
	    //count = ran.nextInt(2);
		ImageView i = (ImageView) this.findViewById(R.id.imageView1);
		i.setFocusable(true);
		if(count ==0)
		{
			DBConnection db = new DBConnection();
			byte[] myByteArray = db.getPic("Select ImagePic from Restaurant where ID=3");
			Bitmap bmp = BitmapFactory.decodeByteArray(myByteArray, 0, myByteArray.length);
		    i.setImageBitmap(bmp);
		}
		
		if(count ==1)
		{
			i.setImageResource(R.drawable.solana_pizza_1);
		}
	}
	private void burger()
	{
		Log.v(TAG, "burger metode");
		Random ran = new Random();
	    count = ran.nextInt(2);
		ImageView i = (ImageView) this.findViewById(R.id.imageView1);
		i.setFocusable(true);
		if(count ==0)
		{
			i.setImageResource(R.drawable.pizzamenu);
		}
		
		if(count ==1)
		{
			i.setImageResource(R.drawable.solana_pizza_1);
		}
	}
}
